<?php defined('YII_ENV') or exit('Access Denied'); ?>
<style>
    .set-el-button {
        padding: 0!important;
        border: 0;
        margin: 0 5px;
    }
    .sort-input {
        width: 100%;
        background-color: #F3F5F6;
        height: 32px;
    }

    .sort-input span {
        height: 32px;
        width: 100%;
        line-height: 32px;
        display: inline-block;
        padding: 0 10px;
        font-size: 13px;
    }

    .sort-input .el-input__inner {
        height: 32px;
        line-height: 32px;
        background-color: #F3F5F6;
        float: left;
        padding: 0 10px;
        border: 0;
    }

    .table-body {
        padding: 20px;
        background-color: #fff;
    }

    .table-info .el-button {
        padding: 0 !important;
        border: 0;
        margin: 0 5px;
    }

    .input-item {
        display: inline-block;
        width: 250px;
        margin: 0 0 20px;
    }

    .input-item .el-input__inner {
        border-right: 0;
    }

    .input-item .el-input__inner:hover{
        border: 1px solid #dcdfe6;
        border-right: 0;
        outline: 0;
    }

    .input-item .el-input__inner:focus{
        border: 1px solid #dcdfe6;
        border-right: 0;
        outline: 0;
    }

    .input-item .el-input-group__append {
        background-color: #fff;
        border-left: 0;
        width: 10%;
        padding: 0;
    }

    .input-item .el-input-group__append .el-button {
        padding: 0;
    }

    .input-item .el-input-group__append .el-button {
        margin: 0;
    }

    .el-table__row td {
        padding: 1px 0;
    }

</style>
<div id="app" v-cloak>
    <el-card shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
        <div slot="header">
            <span>油枪管理</span>
            <el-button style="float: right; margin: -5px 0" type="primary" size="small" @click="$navigate({r:'plugin/scan_code_pay/mall/jiayou/edit'})">新增
            </el-button>
        </div>
        <div class="table-body">
            <div class="input-item">
                <el-input @keyup.enter.native="search" size="small" placeholder="请输入抢号或者油型" v-model="keyword" clearable @clear="search">
                    <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
                </el-input>
            </div>
            <el-table
                v-loading="listLoading"
                :data="list"
                border
                style="width: 100%">
                <el-table-column
                    prop="id"
                    label="ID"
                    width="100">
                </el-table-column>
                <el-table-column
                    label="门店" width="350px">
                    <template slot-scope="scope">
                        <div style="word-break:break-all;-webkit-line-clamp: 1;height: 25px;display: -webkit-box;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;">
                            {{scope.row.store_name}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="抢号">
                    <template slot-scope="scope">
                        <div style="word-break:break-all;-webkit-line-clamp: 1;height: 25px;display: -webkit-box;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;">
                            {{scope.row.qianghao}}
                        </div>
                    </template>
                </el-table-column>

                <el-table-column
                    label="油型">
                    <template slot-scope="scope">
                        <div style="word-break:break-all;-webkit-line-clamp: 1;height: 25px;display: -webkit-box;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;">
                            {{scope.row.youxing}}
                        </div>
                    </template>
                </el-table-column>


                <el-table-column
                    label="直减">
                    <template slot-scope="scope">
                        <div style="word-break:break-all;-webkit-line-clamp: 1;height: 25px;display: -webkit-box;-webkit-box-orient:vertical;overflow:hidden;text-overflow:ellipsis;">
                            {{scope.row.js_money}}
                        </div>
                    </template>
                </el-table-column>


                <el-table-column
                    label="操作"
                    fixed="right"
                    width="220">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row.id)" type="text" circle size="mini">
                            <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                                <img src="statics/img/mall/edit.png" alt="">
                            </el-tooltip>
                        </el-button>
                        <el-button @click="destroy(scope.row.id, scope.$index)" circle type="text" size="mini">
                            <el-tooltip class="item" effect="dark" content="删除" placement="top">
                                <img src="statics/img/mall/del.png" alt="">
                            </el-tooltip>
                        </el-button>
                    </template>
                </el-table-column>

            </el-table>
            <div flex="box:last cross:center">

                <div>
                    <el-pagination v-if="pagination" :page-size="pagination.pageSize"
                                   style="display: inline-block;float: right;" background @current-change="pageChange"
                                   layout="prev, pager, next, jumper" :total="pagination.total_count">
                    </el-pagination>
                </div>
            </div>
        </div>
    </el-card>
</div>
<script>
    const app = new Vue({
        el: '#app',
        data() {
            return {
                loading: false,
                list: [],
                keyword: '',
                pagination: null,
                page: 1,
            };
        },

        methods: {
            //搜索
            search() {
                this.page = 1;
                this.loadData();
            },
            handleCenter: function(row, column) {
                let para = Object.assign({ id: column.id }, { is_join: column.is_join });
                request({
                    params: {
                        r: 'mall/coupon/edit-center'
                    },
                    data: para,
                    method: 'post'
                }).then(e => {
                    if (e.data.code === 0) {
                        this.$message({
                            message: e.data.msg,
                            type: 'success'
                        });

                    } else {
                        this.$alert(e.data.msg, '提示', {
                            confirmButtonText: '确定'
                        })
                    }
                }).catch(e => {});

            },
            //带着ID前往编辑页面
            handleEdit: function(row, column) {
                navigateTo({ r: 'plugin/scan_code_pay/mall/jiayou/edit', id: column.id });
            },



            //分页
            pageChange(page) {
                this.page = page;
                this.loadData();
            },

            //删除
            handleDel: function(row, column) {
                this.$confirm('确认删除该记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.loading = true;
                    let para = { id: column.id };
                    request({
                        params: {
                            r: 'plugin/scan_code_pay/mall/jiayou/destroy'
                        },
                        data: para,
                        method: 'post'
                    }).then(e => {
                        this.loading = false;
                        if (e.data.code === 0) {
                            const h = this.$createElement;
                            this.$message({
                                message: '删除成功',
                                type: 'success'
                            });
                            setTimeout(() => {
                                this.loadData()
                            }, 300);
                        } else {
                            this.$alert(e.data.msg, '提示', {
                                confirmButtonText: '确定'
                            })
                        }
                    }).catch(e => {
                        this.$alert(e.data.msg, '提示', {
                            confirmButtonText: '确定'
                        })
                    });
                })
            },
            // 根据参数获取请求信息
            loadData() {
                this.loading = true;
                request({
                    params: {
                        r: 'plugin/scan_code_pay/mall/jiayou/index',
                        keyword: this.keyword,
                        page: this.page,
                    },
                }).then(e => {
                    this.loading = false;
                    if (e.data.code === 0) {
                        this.list = e.data.data.list;
                        this.pagination = e.data.data.pagination;
                    } else {
                        this.listLoading = false;
                        this.$message({
                            message: e.data.msg,
                            type: 'error'
                        });
                    }
                }).catch(e => {
                    this.listLoading = false;
                });
            }
        },
        created() {
            this.loadData();
        }
    })
</script>